﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectRoleGroup.aspx.cs" Inherits="Thksoft.BusinessExpansion.PublicShow.SelectRoleGroup" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>角色组选择</title>
    <base target="_self" />
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <script type="text/javascript">
        var ModalData = {
            Text: "",
            Value: ""
        };
        function FORM_SUBMIT(dataStr) {
            var data = dataStr.split('%');

            ModalData.Text = data[1];
            ModalData.Value = data[0];
            //调用 父级页面关闭页面
            var index = top.layer.getFrameIndex(window.name); //获取窗口索引
            top.$("#layui-layer" + index + " .layui-layer-close").click();
        }
        //关闭表单
        function FORM_CLOSE() {
            var index = top.layer.getFrameIndex(window.name); //获取窗口索引
            top.console.log("index:" + index);
            top.$("#layui-layer" + index + " .layui-layer-close").click();
        }

        function goDeeperChecked(obj) {
            var chk1 = true;
            // Get the parent.
            var head1 = obj.parentNode.previousSibling;
            // no rows, cant do my work.
            if (obj.rows == null) {
                return;
            }
            // This is how may rows are at this level.
            var pTreeLevel1 = obj.rows[0].cells.length;
            // Are we a parentmy ?
            if (head1.tagName == "TABLE") {
                // Get the list of rows ahead of us.
                var tbls = obj.parentNode.getElementsByTagName("TABLE");
                // get the count of that list.
                var tblsCount = tbls.length;
                // determine if any of the rows underneath are unchecked.
                for (i = 0; i < tblsCount; i++) {
                    var childTreeLevel = tbls[i].rows[0].cells.length;
                    if (childTreeLevel = pTreeLevel1) {
                        var chld = tbls[i].getElementsByTagName("INPUT");
                        if (chld[0].checked == false) {
                            chk1 = false;
                            break;
                        }
                    }
                }
                var nd = head1.getElementsByTagName("INPUT");
                nd[0].checked = chk1;
                // do the same for the level above
                goDeeperChecked(obj.parentNode);
            }
            else {
                return;
            }
        }

        function goDeeper(check, obj) {
            // head1 gets the parent node of the unchecked node
            var head = obj.parentNode.previousSibling;
            if (head.tagName == "TABLE") {
                // checks for the input tag which consists of checkbox
                var matchElement = head.getElementsByTagName("INPUT");
                // matchElement1[0] gives us the checkbox and it is unchecked
                matchElement[0].checked = false;
            }
            else {
                head = obj.parentNode.previousSibling;
            }
            if (head.tagName == "TABLE") {
                goDeeper(check, obj.parentNode);
            }

            else {
                return;
            }
        }

        function treeViewCheck(event) {
            // obj gives us the node on which check or uncheck operation has performed
            var obj = event.srcElement || event.target;
            var treeNodeFound = false;
            var checkedState;
            // checking whether obj consists of checkbox to avoid exception
            if (obj.tagName == "INPUT" && obj.type == "checkbox") {
                var treeNode = obj;
                checkedState = treeNode.checked;
                // work our way back to the parent < table > element
                do {
                    obj = obj.parentNode;
                }
                while (obj.tagName != "TABLE")
                var parentTreeLevel = obj.rows[0].cells.length;
                var parentTreeNode = obj.rows[0].cells[0];
                // get all the TreeNodes inside the TreeView (the parent < div > )
                var tables = obj.parentNode.getElementsByTagName("TABLE");
                // checking for any node is checked or unchecked during operation
                if (obj.tagName == "TABLE") {
                    // if any node is unchecked then their parent node are unchecked
                    if (!treeNode.checked) {
                        goDeeper(false, obj);
                    }

                    // end if - unchecked
                    // total number of TreeNodes
                    var numTables = tables.length
                    if (numTables >= 1) {
                        // cycle through all the TreeNodes
                        // until we find the TreeNode we checked
                        for (i = 0; i < numTables; i++) {
                            if (tables[i] == obj) {
                                treeNodeFound = true;
                                i++;
                                if (i == numTables) {
                                    // if we're on the last TreeNode, we are done
                                    break;
                                }
                            }

                            if (treeNodeFound == true) {
                                var childTreeLevel = tables[i].rows[0].cells.length;
                                if (childTreeLevel > parentTreeLevel) {
                                    var cell = tables[i].rows[0].cells[childTreeLevel - 1];

                                    var inputs = cell.getElementsByTagName("INPUT");
                                    inputs[0].checked = checkedState;
                                }

                                else {

                                    break;
                                }
                            }

                        }

                    }

                    if (treeNode.checked) {
                        goDeeperChecked(obj);
                    }

                }

            }

        }
        function Load() {
            var winHeight = document.documentElement.clientHeight;
            var ob = document.getElementById("InfoDiv");
            var mendingTop = ob.offsetTop;
            while (ob != null && ob.offsetParent != null && ob.offsetParent.tagName != "BODY") {
                mendingTop += ob.offsetParent.offsetTop;
                ob = ob.offsetParent;
            }
            if (winHeight - mendingTop - 10 > 5) {
                document.getElementById("InfoDiv").style.height = winHeight - mendingTop - 10 + "px";
            }
            else {
                document.getElementById("InfoDiv").style.height = "20px";
            }
        }
    </script>
</head>
<body style="overflow-x: hidden; background-color: #E6EAEC;">
    <form id="form1" runat="server">
        <asp:HiddenField ID="FORM_MODE" runat="server" />
        <center style="overflow-x: hidden; overflow-y: hidden;">
            <div>
                <table border="0" cellpadding="0" cellspacing="0" style="width: 99%;" class="table">
                    <tr>
                        <td colspan="4" style="padding-bottom: 5px; text-align: center;">
                            <asp:Button ID="btnOk" runat="server" CssClass="bt_css_s" Text="确 定" OnClick="btnOk_Click" />
                            &nbsp;
                        <input type="button" class="bt_css_s" value="取 消" onclick="FORM_CLOSE()" />
                        </td>
                    </tr>
                </table>
            </div>
            <div id="InfoDiv" runat="server" style="border: 1px double #b0b0b0; margin-left: 15px; width: 387px; font-size: 12px; font-weight: 400; text-align: left; color: #1f1f1f; overflow-y: auto; overflow-x: hidden;">
                <asp:TreeView ID="MyTree" runat="server" ShowCheckBoxes="All" Height="400px" Width="387px"
                    onclick="treeViewCheck(event) ;">
                    <DataBindings>
                        <asp:TreeNodeBinding DataMember="Category" ValueField="ID" TextField="Name"></asp:TreeNodeBinding>
                        <asp:TreeNodeBinding DataMember="Description" ValueField="Value" TextField="Value"></asp:TreeNodeBinding>
                    </DataBindings>
                </asp:TreeView>
            </div>
        </center>
    </form>
</body>
</html>